//
//  ViewController.m
//  URLDemo
//
//  Created by 李煜 on 2021/9/6.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view.
//    NSString *urltest = @"https://www.jianshu.com/p/387c3c6b04b9";
    NSString *urltest = @"file:///Users/liyu/Library/Developer/CoreSimulator/Devices/F70505C2-C438-4433-9BD7-D9F8A1B1C3FD/data/Containers/Data/Application/1D736F01-C7D6-4396-8F32-77D5AE4CCF1C/Library/Caches/__UNI__A88668C.wgt";
    NSURL *url = [NSURL URLWithString:urltest];
    NSDictionary*dict =@{@"name":@"xiaoqiang"};
    NSString*filePath =@"/Users/liyu/Desktop/name.plist";
    NSString*fileURL =@"file:///Users/liyu/Desktop/name.plist";
    NSURL*url1 = [NSURL URLWithString:fileURL];//            file:///Users/liyu/Desktop/name.plist
    NSURL*url2 = [NSURL fileURLWithPath:filePath];//        file:///Users/liyu/Desktop/name.plist
    NSURL*url3 = [NSURL URLWithString:filePath];//          /Users/liyu/Desktop/name.plist
    NSURL*url4 = [NSURL fileURLWithPath:fileURL];//         file:/Users/liyu/Desktop/name.plist -- file:///     ❌
    NSLog(@"url1 = %@\n url2 = %@\n url3 = %@",url1,url2,url3);
    //    [dict writeToFile:filePath atomically:YES];//可以生成
    //    [dict writeToFile:fileURL atomically:YES]; //无法生成 —>路径中不能包含协议头
    //    [dict writeToURL:url1 atomically:YES]; //可以生成
    //    [dict writeToURL:url2 atomically:YES]; //可以生成
    [dict writeToURL:url3 atomically:YES]; //无法生成 —>字符串中必须包含协议头,不然生成的URL是错误的;
    
}


@end
